package com.xtkj.fcsjgromoreads.flutter;

import androidx.annotation.NonNull;

import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.plugin.common.EventChannel;
import io.flutter.plugin.common.MethodChannel;

public class FCsjGroMoreAdsPlugin implements FlutterPlugin, ActivityAware {
    // 方法通道
    private MethodChannel mMethodChannel;
    // 消息通道
    private EventChannel mEventChannel;
    // 插件代理
    private FCsjGroMoreAdsPluginDelegate mPluginDelegate;
    // 插件bind
    private FlutterPluginBinding mPluginBinding;
    @Override
    public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
        mPluginBinding = binding;
        mMethodChannel = new MethodChannel(binding.getBinaryMessenger(),"com.xt.fcsj.gromore.ads");
        mEventChannel = new EventChannel(binding.getBinaryMessenger(),"com.xt.fcsj.gromore.ads.event");
    }

    @Override
    public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
        mMethodChannel.setMethodCallHandler(null);
        mEventChannel.setStreamHandler(null);
    }

    @Override
    public void onAttachedToActivity(@NonNull ActivityPluginBinding binding) {
        mPluginDelegate = new FCsjGroMoreAdsPluginDelegate(mPluginBinding,binding.getActivity());
        //将方法事件统一交给代理
        mMethodChannel.setMethodCallHandler(mPluginDelegate);
        //将消息事件统一交给代理
        mEventChannel.setStreamHandler(mPluginDelegate);
    }

    @Override
    public void onDetachedFromActivityForConfigChanges() {
        onDetachedFromActivity();
    }

    @Override
    public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding) {
        onAttachedToActivity(binding);
    }

    @Override
    public void onDetachedFromActivity() {
        mPluginDelegate = null;
    }
}
